package 多线程;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class UserThreadPool {
	
//	int corePoolSize ,  常驻核心线程数
//	int maximumPoolSize, 最大线程数
//	long keepAliveTime , 线程池中的线程空闲时间
//	TimeUnit.SECONDS
//	BlockingQueue<runnable> workQueue , 缓存队列
//	ThreadFactory threadFactory, 线程工厂 用来生产一组相同任务的线程
//	RejectedExecutionHandler handler) 表示执行拒绝策略的对象

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		BlockingQueue queue = new LinkedBlockingQueue(2);
		UserThreadFactory f1 = new UserThreadFactory("第1机房");
		UserThreadFactory f2 = new UserThreadFactory("第2机房");
		
		UserRejectHandler handler = new UserRejectHandler();
		ThreadPoolExecutor threadPoolFirst = new ThreadPoolExecutor(1, 2, 60, 
				TimeUnit.SECONDS, queue, f1, handler);
		ThreadPoolExecutor threadPoolSecond = new ThreadPoolExecutor(1, 2, 60, 
				TimeUnit.SECONDS, queue, f2, handler);
		
		// 创建400个任务线程
		Runnable task = new Task();
		for (int i = 0; i < 200; i++) {
			threadPoolFirst.execute(task);
			threadPoolSecond.execute(task);
		}

	}

}
